/*
 * Name: $RCSfile: DownloadString.java,v $
 * Version: $Revision: 1.1 $
 * Date: $Date: Dec 15, 2011 1:56:00 PM $
 *
 * Copyright (C) 2011 DirecTV, Inc. All rights reserved.
 */
package com.admissions.network;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

import com.admissions.common.Constants;

/***
 * this class is used to download data from web service api
 * 
 * @author LongNH
 * 
 */
public class HttpNetService implements Constants {

	/**
	 * 
	 * @param url
	 * @return
	 */
	public static String getJsonByURL(String url) {
		String content = "";

		try {
			HttpClient client = new DefaultHttpClient();
			HttpGet request = new HttpGet(url);
			HttpResponse response = client.execute(request);

			InputStream in = response.getEntity().getContent();
			BufferedReader reader = new BufferedReader(new InputStreamReader(in));
			StringBuilder str = new StringBuilder();
			String line = null;
			while ((line = reader.readLine()) != null) {
				str.append(line);
			}
			in.close();
			content = str.toString();
		} catch (Exception e) {
			e.printStackTrace();
		}

		return content;
	}
}
